<?php 
    session_start();
    if(!isset($_SESSION['islogined']))
        header("location:./Login.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="app.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
    <?php include 'header1.php'; ?>
    <div class="container">
        <ol class="breadcrumb path-nav">
            <li><a href="./Home.php">Home</a></li>
            <li class="active">Staff Management</li>
        </ol>
    </div>
    <div class="container">
        <div class="col-xs-3 col-md-3 col-lg-3">
            <ul class="list-group">
                <li class="list-group-item active" data-id="0">All Staff</li>
                <li class="list-group-item" data-id="1">Head of Department</li>
                <li class="list-group-item" data-id="2">Secretary</li>
                <li class="list-group-item" data-id="3">Academic Staff</li>
            </ul>
            
            <?php
                $idposition=$_SESSION['idposition'];
                if($idposition==1||$idposition==2){
                    echo"
                    <button type='button' class='btn btn-default btn-lg btn-block'>
                    <span class='glyphicon glyphicon-plus'></span> Add New Member
                    </button>";
                }
            ?>
                
            
        </div>

        <div id="infor_staff" class="col-xs-9 col-md-9 col-lg-9">
            <?php 
                include'infor_staff.php';
                $sql="SELECT * FROM staff WHERE idposition is not null";
                getinfor($sql);
            ?>
        </div>
    </div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<script src="jquery-3.0.0.min.js"></script>
<script src="bootstrap.min.js"></script>
<script>
    $(function(){
        buttonclick();
        $(".list-group-item").click(function(){
            $(".success-modify").remove();
            $(".list-group-item").removeClass("active");
            var str=$(this).data('id');
            $(this).addClass("active");
            $.get("infor_staff.php?id="+str,null,function(data){
                $('#infor_staff').html(data);
                buttonclick();      	        
            })
        });
        $(".btn-block").click(function(){
            $(window).attr('location','AddStaff.php');
        });
        $(document).on('click','#delete_staff',function(){
            $(".success-modify").remove();
            var staffname=$(this).data('name');
            $.post('infor_staff.php',{
                type:"delete_staff",
                staffname:staffname
            },function(){
                $("#"+staffname).hide();
                $("#infor_staff").before("<div class='success-modify'>The staff has deleted successfully</div>")
            })
        });
   });
   function buttonclick(){
       $(".st_button").click(function(){
            var name=$(this).data('username');
            var type=$(this).data('type');
            $.get("infor_staff.php?username="+name+"&type="+type,null,function(data){
                $('#myModal').html(data);                
                $('#myModal').modal();
                viewtask();
            })
        });
   }
   function viewtask(){
       $(".viewtask").click(function(){
           var id=$(this).data('id');
           $('.'+id).toggle();
       });
       $("#m_sub_button").click(function(){
           var id=$(this).data('id');
           var f_type=$("#type").val();
           var f_staffname=$("#staffname").val();
           var f_title=$("#title").val();
           var f_firstname=$("#firstname").val();
           var f_lastname=$("#lastname").val();
           var f_email=$("#email").val();
           var f_phoneNo=$("#phoneNo").val();
           var f_position=$("#position").val();
           $.post("staff_infor_change.php",{
               type:f_type,
               staffname:f_staffname,
               title:f_title,
               firstname:f_firstname,
               lastname:f_lastname,
               email:f_email,
               phoneNo:f_phoneNo,
               position:f_position
           },function (data){
               $('.success-modify').remove();
               $('#'+id).html(data);
               buttonclick();
           })
       });
       $(".subtemplete").unbind('click').bind('click',function(){
            if($(this).hasClass('glyphicon-triangle-bottom')){
                $(this).removeClass('glyphicon-triangle-bottom');
                $(this).addClass('glyphicon-triangle-left');
            }
            else{
                $(this).removeClass('glyphicon-triangle-left');
                $(this).addClass('glyphicon-triangle-bottom');
            }
            var id=$(this).data('id');
            $("."+id).toggle();
        });
   }
</script>

</body>
</html>
